
<!DOCTYPE html>
<html lang="zh-Hans" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Node学习(六) --基本模块 - 默默默默燃</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="TriDiamond Obsidian,"> 
    <meta name="description" content="一枚前端搬砖队队员的记录册,assert (断言)assert（断言）通常用来对代码进行校验，若出错则阻止程序运行，并抛出一个错误。
用法12345const assert = require(&#39;assert&#39;)assert(,"> 
    <meta name="author" content="张白告丶"> 
    <link rel="alternative" href="atom.xml" title="默默默默燃" type="application/atom+xml"> 
    <link rel="icon" href="/img/favicon.png"> 
    <link href="https://fonts.loli.net/css?family=Roboto+Mono|Rubik&display=swap" rel="stylesheet">
    
<link rel="stylesheet" href="//at.alicdn.com/t/font_1429596_nzgqgvnmkjb.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.7.2/animate.min.css">

    
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/codemirror.min.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/theme/dracula.css">

    
<link rel="stylesheet" href="/css/obsidian.css">

    
<link rel="stylesheet" href="/css/ball-atom.min.css">

<meta name="generator" content="Hexo 4.2.0"></head>


<body class="loading">
    <div class="loader">
        <div class="la-ball-atom la-2x">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <span id="config-title" style="display:none">默默默默燃</span>
    <div id="loader"></div>
    <div id="single">
    <div class="scrollbar gradient-bg-rev"></div>
<div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <div class="navigation animated fadeIn fast delay-1s">
        <img id="home-icon" class="icon-home" src="/img/favicon.png" alt="" data-url="https://zhanghao-web.github.io">
        <div id="play-icon" title="Play/Pause" class="iconfont icon-play"></div>
        <h3 class="subtitle">Node学习(六) --基本模块</h3>
        <div class="social">
            <!--        <div class="like-icon">-->
            <!--            <a href="javascript:;" class="likeThis active"><span class="icon-like"></span><span class="count">76</span></a>-->
            <!--        </div>-->
            <div>
                <div class="share">
                    
                        <a href="javascript:;" class="iconfont icon-share1"></a>
                        <div class="share-component-cc" data-disabled="facebook,douban,linkedin,diandian,tencent,google"></div>
                    
                </div>
            </div>
        </div>
    </div>
</div>

    <div class="section">
        <div class=article-header-wrapper>
    <div class="article-header">
        <div class="article-cover animated fadeIn" style="
            animation-delay: 600ms;
            animation-duration: 1.2s;
            background-image: 
                radial-gradient(ellipse closest-side, rgba(0, 0, 0, 0.65), #100e17),
                url(/img/cover.jpg) ">
        </div>
        <div class="else">
            <p class="animated fadeInDown">
                
                <a href="/categories/Node"><b>「
                    </b>NODE<b> 」</b></a>
                
                April 01, 2019
            </p>
            <h3 class="post-title animated fadeInDown"><a href="/2019/04/01/Node/Node%E5%AD%A6%E4%B9%A0(%E5%85%AD)%20--%E5%9F%BA%E6%9C%AC%E6%A8%A1%E5%9D%97/" title="Node学习(六) --基本模块" class="">Node学习(六) --基本模块</a>
            </h3>
            
            <p class="post-count animated fadeInDown">
                
                <span>
                    <b class="iconfont icon-text2"></b> <i>Words count</i>
                    26k
                </span>
                
                
                <span>
                    <b class="iconfont icon-timer__s"></b> <i>Reading time</i>
                    24 mins.
                </span>
                
                
                
                <span id="busuanzi_container_page_pv">
                    <b class="iconfont icon-read"></b> <i>Read count</i>
                    <span id="busuanzi_value_page_pv">0</span>
                </span>
                
            </p>
            
            
            <ul class="animated fadeInDown post-tags-list" itemprop="keywords"><li class="animated fadeInDown post-tags-list-item"><a class="animated fadeInDown post-tags-list-link" href="/tags/Node/" rel="tag">Node</a></li></ul>
            
        </div>
    </div>
</div>

<div class="screen-gradient-after">
    <div class="screen-gradient-content">
        <div class="screen-gradient-content-inside">
            <div class="bold-underline-links screen-gradient-sponsor">
                <p>
                    <span class="animated fadeIn delay-1s"></span>
                </p>
            </div>
        </div>
    </div>
</div>

<div class="article">
    <div class='main'>
        <div class="content markdown animated fadeIn">
            <h2 id="assert-断言"><a href="#assert-断言" class="headerlink" title="assert (断言)"></a>assert (断言)</h2><p>assert（断言）通常用来对代码进行校验，若出错则阻止程序运行，并抛出一个错误。</p>
<h3 id="用法"><a href="#用法" class="headerlink" title="用法"></a>用法</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> assert = <span class="built_in">require</span>(<span class="string">'assert'</span>)</span><br><span class="line"></span><br><span class="line">assert(<span class="number">2</span> &gt; <span class="number">1</span>, <span class="string">'2 &gt; 1'</span>)</span><br><span class="line"></span><br><span class="line">assert(<span class="number">1</span> &gt; <span class="number">2</span>, <span class="string">'1 &gt; 2'</span>)</span><br></pre></td></tr></table></figure>
<p>代码在运行到assert(2 &gt; 1, ‘2 &gt; 1’)时，由于2 &gt; 1为true，此时不会抛出错误。</p>
<p>而运行到assert(1 &gt; 2, ‘1 &gt; 2’)时，由于1 &gt; 2为false，此时会抛出错误如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">AssertionError [ERR_ASSERTION]: <span class="number">1</span> &gt; <span class="number">2</span></span><br><span class="line">    at <span class="built_in">Object</span>.&lt;anonymous&gt; (C:\projects\nodejs-tutorial\lesson11\assert.js:<span class="number">5</span>:<span class="number">1</span>)</span><br><span class="line">    at Module._compile (internal/modules/cjs/loader.js:<span class="number">734</span>:<span class="number">30</span>)</span><br><span class="line">    at <span class="built_in">Object</span>.Module._extensions..js (internal/modules/cjs/loader.js:<span class="number">745</span>:<span class="number">10</span>)</span><br><span class="line">    at Module.load (internal/modules/cjs/loader.js:<span class="number">626</span>:<span class="number">32</span>)</span><br><span class="line">    at tryModuleLoad (internal/modules/cjs/loader.js:<span class="number">566</span>:<span class="number">12</span>)</span><br><span class="line">    at <span class="built_in">Function</span>.Module._load (internal/modules/cjs/loader.js:<span class="number">558</span>:<span class="number">3</span>)</span><br><span class="line">    at <span class="built_in">Function</span>.Module.runMain (internal/modules/cjs/loader.js:<span class="number">797</span>:<span class="number">12</span>)</span><br><span class="line">    at executeUserCode (internal/bootstrap/node.js:<span class="number">526</span>:<span class="number">15</span>)</span><br><span class="line">    at startMainThreadExecution (internal/bootstrap/node.js:<span class="number">439</span>:<span class="number">3</span>)</span><br></pre></td></tr></table></figure>
<h3 id="使用方式"><a href="#使用方式" class="headerlink" title="使用方式"></a>使用方式</h3><p>通常可以在一个模块或函数的每个阶段使用assert，或者在对函数传参进行assert校验，以保证代码运行的正确性。</p>
<h3 id="assert-deepStrictEqual"><a href="#assert-deepStrictEqual" class="headerlink" title="assert.deepStrictEqual"></a>assert.deepStrictEqual</h3><p><code>assert.deepStrictEqual(actual, expected[, message])</code>用于对actual 参数和 expected的深度比较，即不仅校验它们是否相等，同时也要校验它们的成员之间是否相等。</p>
<p><code>assert.deepStrictEqual</code>在校验对象或数组时比较有用。</p>
<p><code>assert.deepStrictEqual</code>的比较相当于<code>===</code>，也就是不仅是值相等，值的类型也要相等。</p>
<h3 id="assert-deepStrictEqual的用法"><a href="#assert-deepStrictEqual的用法" class="headerlink" title="assert.deepStrictEqual的用法"></a>assert.deepStrictEqual的用法</h3><p>1.使用<code>assert.deepStrictEqual</code>比较对象：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> assert = <span class="built_in">require</span>(<span class="string">'assert'</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> obj1 = &#123;</span><br><span class="line">  a: <span class="number">1</span>,</span><br><span class="line">  b: <span class="number">2</span>,</span><br><span class="line">  children: &#123;</span><br><span class="line">    c: <span class="number">3</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> obj2 = &#123;</span><br><span class="line">  a: <span class="number">1</span>,</span><br><span class="line">  b: <span class="number">2</span>,</span><br><span class="line">  children: &#123;</span><br><span class="line">    c: <span class="number">3</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> obj3 = &#123;</span><br><span class="line">  a: <span class="number">1</span>,</span><br><span class="line">  b: <span class="number">2</span>,</span><br><span class="line">  children: &#123;</span><br><span class="line">    c: <span class="string">'3'</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">assert.deepStrictEqual(obj1, obj2, <span class="string">'obj1 !== obj2'</span>)</span><br><span class="line"></span><br><span class="line">assert.deepStrictEqual(obj1, obj3, <span class="string">'obj1 !== obj3'</span>)</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<p>代码会抛出错误：obj1 !== obj3。</p>
<p>2.使用<code>assert.deepStrictEqual</code>比较数组</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> assert = <span class="built_in">require</span>(<span class="string">'assert'</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> arr1 = [&#123;</span><br><span class="line">  a: <span class="number">1</span>,</span><br><span class="line">  b: <span class="number">2</span>,</span><br><span class="line">  children: [&#123;</span><br><span class="line">    c: <span class="number">3</span></span><br><span class="line">  &#125;]</span><br><span class="line">&#125;]</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> arr2 = [&#123;</span><br><span class="line">  a: <span class="number">1</span>,</span><br><span class="line">  b: <span class="number">2</span>,</span><br><span class="line">  children: [&#123;</span><br><span class="line">    c: <span class="number">3</span></span><br><span class="line">  &#125;]</span><br><span class="line">&#125;]</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> arr3 = [&#123;</span><br><span class="line">  a: <span class="number">1</span>,</span><br><span class="line">  b: <span class="number">2</span>,</span><br><span class="line">  children: [&#123;</span><br><span class="line">    c: <span class="string">'3'</span></span><br><span class="line">  &#125;]</span><br><span class="line">&#125;]</span><br><span class="line"></span><br><span class="line">assert.deepStrictEqual(arr1, arr2, <span class="string">'arr1 !== arr2'</span>)</span><br><span class="line"></span><br><span class="line">assert.deepStrictEqual(arr1, arr3, <span class="string">'arr1 !== arr3'</span>)</span><br></pre></td></tr></table></figure>
<h2 id="path-路径"><a href="#path-路径" class="headerlink" title="path(路径)"></a>path(路径)</h2><p>path模块主要用来对文件路径进行处理，比如提取路径、后缀，拼接路径等。</p>
<h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> path = <span class="built_in">require</span>(<span class="string">'path'</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> str = <span class="string">'/root/a/b/1.txt'</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(path.dirname(str))  <span class="comment">// 获取文件目录：/root/a/b</span></span><br><span class="line"><span class="built_in">console</span>.log(path.basename(str)) <span class="comment">// 获取文件名：1.txt</span></span><br><span class="line"><span class="built_in">console</span>.log(path.extname(str)) <span class="comment">// 获取文件后缀：.txt</span></span><br><span class="line"><span class="built_in">console</span>.log(path.resolve(str, <span class="string">'../c'</span>, <span class="string">'build'</span>, <span class="string">'strict'</span>)) <span class="comment">// 将路径解析为绝对路径：C:\root\a\b\c\build\strict</span></span><br><span class="line"><span class="built_in">console</span>.log(path.resolve(str, <span class="string">'../c'</span>, <span class="string">'build'</span>, <span class="string">'strict'</span>, <span class="string">'../..'</span>, <span class="string">'assets'</span>)) <span class="comment">// 将路径解析为绝对路径：C:\root\a\b\c\assets</span></span><br><span class="line"><span class="built_in">console</span>.log(path.resolve(__dirname, <span class="string">'build'</span>)) <span class="comment">// 将路径解析为绝对路径：C:\projects\nodejs-tutorial\lesson12\build</span></span><br></pre></td></tr></table></figure>
<p>值得一提的是<code>path.resolve</code>方法，它可以接收任意个参数，然后根据每个路径参数之间的关系，将路径最终解析为一个<em>绝对路径</em>。</p>
<p><code>__dirname</code>指的是当前模块所在的绝对路径名称，它的值会自动根据当前的绝对路径变化，等同于<code>path.dirname(__filename)</code>的结果。</p>
<h2 id="URL模块"><a href="#URL模块" class="headerlink" title="URL模块"></a>URL模块</h2><h3 id="url-parse"><a href="#url-parse" class="headerlink" title="url.parse"></a>url.parse</h3><p>URL模块用于对URL的解析，常用的是url.parse方法。</p>
<p>假设有一个url为<code>https://www.google.com:8080/a/b?x=1&amp;y=2&amp;y=3&amp;y=4</code>，可以用url.parse方法进行解析。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> url = <span class="built_in">require</span>(<span class="string">'url'</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> str = <span class="string">'https://www.google.com:8080/a/b?x=1&amp;y=2&amp;y=3&amp;y=4'</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(url.parse(str))</span><br></pre></td></tr></table></figure>
<p>打印结果如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">Url &#123;</span><br><span class="line">  protocol: <span class="string">'https:'</span>,</span><br><span class="line">  slashes: <span class="literal">true</span>,</span><br><span class="line">  auth: <span class="literal">null</span>,</span><br><span class="line">  host: <span class="string">'www.google.com:8080'</span>,</span><br><span class="line">  port: <span class="string">'8080'</span>,</span><br><span class="line">  hostname: <span class="string">'www.google.com'</span>,</span><br><span class="line">  hash: <span class="literal">null</span>,</span><br><span class="line">  search: <span class="string">'?x=1&amp;y=2&amp;y=3&amp;y=4'</span>,</span><br><span class="line">  query: <span class="string">'x=1&amp;y=2&amp;y=3&amp;y=4'</span>,</span><br><span class="line">  pathname: <span class="string">'/a/b'</span>,</span><br><span class="line">  path: <span class="string">'/a/b?x=1&amp;y=2&amp;y=3&amp;y=4'</span>,</span><br><span class="line">  href: <span class="string">'https://www.google.com:8080/a/b?x=1&amp;y=2&amp;y=3&amp;y=4'</span> &#125;</span><br></pre></td></tr></table></figure>
<p>可以看到url的信息如端口号、域名、query参数等都被解析出来了。</p>
<p>如果需要将query参数转为对象，则可以为url.parse函数的第二个参数传true，如<code>console.log(url.parse(str, true))</code>，打印结果如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">Url &#123;</span><br><span class="line">  protocol: <span class="string">'https:'</span>,</span><br><span class="line">  slashes: <span class="literal">true</span>,</span><br><span class="line">  auth: <span class="literal">null</span>,</span><br><span class="line">  host: <span class="string">'www.google.com:8080'</span>,</span><br><span class="line">  port: <span class="string">'8080'</span>,</span><br><span class="line">  hostname: <span class="string">'www.google.com'</span>,</span><br><span class="line">  hash: <span class="literal">null</span>,</span><br><span class="line">  search: <span class="string">'?x=1&amp;y=2&amp;y=3&amp;y=4'</span>,</span><br><span class="line">  query: [<span class="built_in">Object</span>: <span class="literal">null</span> prototype] &#123; <span class="attr">x</span>: <span class="string">'1'</span>, <span class="attr">y</span>: [ <span class="string">'2'</span>, <span class="string">'3'</span>, <span class="string">'4'</span> ] &#125;,</span><br><span class="line">  pathname: <span class="string">'/a/b'</span>,</span><br><span class="line">  path: <span class="string">'/a/b?x=1&amp;y=2&amp;y=3&amp;y=4'</span>,</span><br><span class="line">  href: <span class="string">'https://www.google.com:8080/a/b?x=1&amp;y=2&amp;y=3&amp;y=4'</span> &#125;</span><br></pre></td></tr></table></figure>
<p>同时可以看到y=2&amp;y=3&amp;y=4参数被解析为了y: [ ‘2’, ‘3’, ‘4’ ]。</p>
<h3 id="new-URL"><a href="#new-URL" class="headerlink" title="new URL()"></a>new URL()</h3><p>除了用<code>url.parse</code>方法解析url，还可以通过构造函数URL，创建一个实例，其中带有解析后的数据。</p>
<p>实例有一个toString方法，可以将实例解析为字符串url。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> &#123; URL &#125; = <span class="built_in">require</span>(<span class="string">'url'</span>)</span><br><span class="line"><span class="keyword">const</span> urlObj = <span class="keyword">new</span> URL(str)</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(urlObj)</span><br><span class="line"><span class="built_in">console</span>.log(urlObj.toString())</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">URL &#123;</span><br><span class="line">  href: <span class="string">'https://www.google.com:8080/a/b?x=1&amp;y=2&amp;y=3&amp;y=4'</span>,</span><br><span class="line">  origin: <span class="string">'https://www.google.com:8080'</span>,</span><br><span class="line">  protocol: <span class="string">'https:'</span>,</span><br><span class="line">  username: <span class="string">''</span>,</span><br><span class="line">  password: <span class="string">''</span>,</span><br><span class="line">  host: <span class="string">'www.google.com:8080'</span>,</span><br><span class="line">  hostname: <span class="string">'www.google.com'</span>,</span><br><span class="line">  port: <span class="string">'8080'</span>,</span><br><span class="line">  pathname: <span class="string">'/a/b'</span>,</span><br><span class="line">  search: <span class="string">'?x=1&amp;y=2&amp;y=3&amp;y=4'</span>,</span><br><span class="line">  searchParams:</span><br><span class="line">   URLSearchParams &#123; <span class="string">'x'</span> =&gt; <span class="string">'1'</span>, <span class="string">'y'</span> =&gt; <span class="string">'2'</span>, <span class="string">'y'</span> =&gt; <span class="string">'3'</span>, <span class="string">'y'</span> =&gt; <span class="string">'4'</span> &#125;,</span><br><span class="line">  hash: <span class="string">''</span> &#125;</span><br><span class="line">  </span><br><span class="line">https:<span class="comment">//www.google.com:8080/a/b?x=1&amp;y=2&amp;y=3&amp;y=4	// toString方法解析出的url</span></span><br></pre></td></tr></table></figure>
<h2 id="querystring模块"><a href="#querystring模块" class="headerlink" title="querystring模块"></a>querystring模块</h2><p>querystring用来对url中的query字符串进行解析，常用的方法有<code>querystring.parse</code>和<code>querystring.stringify</code>。</p>
<h3 id="querystring-parse"><a href="#querystring-parse" class="headerlink" title="querystring.parse"></a>querystring.parse</h3><p>querystring.parse方法用于解析URL 查询字符串。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> querystring = <span class="built_in">require</span>(<span class="string">'querystring'</span>)</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(querystring.parse(<span class="string">'foo=bar&amp;abc=xyz&amp;abc=123'</span>))</span><br><span class="line"><span class="comment">//&#123; foo: 'bar', abc: [ 'xyz', '123' ] &#125;</span></span><br></pre></td></tr></table></figure>
<h3 id="querystring-stringify"><a href="#querystring-stringify" class="headerlink" title="querystring.stringify"></a>querystring.stringify</h3><p>querystring.stringify用于将对象转换为URL查询字符串。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(querystring.stringify(&#123; <span class="attr">foo</span>: <span class="string">'bar'</span>, <span class="attr">baz</span>: [<span class="string">'qux'</span>, <span class="string">'quux'</span>], <span class="attr">corge</span>: <span class="string">''</span> &#125;))</span><br><span class="line"></span><br><span class="line"><span class="comment">// foo=bar&amp;baz=qux&amp;baz=quux&amp;corge=</span></span><br></pre></td></tr></table></figure>
<h2 id="net模块"><a href="#net模块" class="headerlink" title="net模块"></a>net模块</h2><p>net 模块用于创建基于流的 TCP 或 IPC 的服务器（net.createServer()）与客户端（net.createConnection()）。</p>
<p>net模块是专门用于网络通信的模块，若当前的数据交互不通过HTTP协议，就可以使用net模块，如<code>WebSocket</code>。</p>
<p>HTTP协议本质上是以文本形式传输数据，它的传输数据量较大，而且它的传输需要二进制和文本之间进行转换和解析。</p>
<p>在nodejs中，HTTP模块是继承自net模块的。</p>
<h3 id="OSI参考模型"><a href="#OSI参考模型" class="headerlink" title="OSI参考模型"></a>OSI参考模型</h3><p>OSI（Open System Interconnect），即开放式系统互联。 它是ISO（国际标准化组织）组织在1985年研究的网络互联模型。该体系结构标准定义了网络互联的七层框架（<strong>物理层、数据链路层、网络层、传输层、会话层、表示层和应用层</strong>），即OSI开放系统互连参考模型。在这一框架下进一步详细规定了每一层的功能，以实现开放系统环境中的互连性、互操作性和应用的可移植性。</p>
<h3 id="OSI参考模型分层"><a href="#OSI参考模型分层" class="headerlink" title="OSI参考模型分层"></a>OSI参考模型分层</h3><p>OSI参考模型可以分为以下七层：</p>
<p><strong>物理层 → 数据链路层 → 网络层（IP协议） → 传输层（TCP层） → 会话层 → 表现层 → 应用层（HTTP协议等）</strong></p>
<p>OSI参考模型详细介绍如下：</p>
<p>第1层物理层：处于OSI参考模型的最底层。物理层的主要功能是利用物理传输介质为数据链路层提供物理连接，以便透明的传送比特流。常用设备有（各种物理设备）网卡、集线器、中继器、调制解调器、网线、双绞线、同轴电缆。</p>
<p>第2层数据链路层：在此层将数据分帧，并处理流控制。屏蔽物理层，为网络层提供一个数据链路的连接，在一条有可能出差错的物理连接上，进行几乎无差错的数据传输（差错控制）。本层指定拓扑结构并提供硬件寻址。常用设备有网桥、交换机；</p>
<p>第3层网络层：本层通过寻址来建立两个节点之间的连接，为源端的运输层送来的分组，选择合适的路由和交换节点，正确无误地按照地址传送给目的端的运输层。它包括通过互连网络来路由和中继数据 ；除了选择路由之外，网络层还负责建立和维护连接，控制网络上的拥塞以及在必要的时候生成计费信息。</p>
<p>第4层传输层：—常规数据递送－面向连接或无连接。为会话层用户提供一个端到端的可靠、透明和优化的数据传输服务机制。包括全双工或半双工、流控制和错误恢复服务；传输层把消息分成若干个分组，并在接收端对它们进行重组。不同的分组可以通过不同的连接传送到主机。这样既能获得较高的带宽，又不影响会话层。在建立连接时传输层可以请求服务质量，该服务质量指定可接受的误码率、延迟量、安全性等参数，还可以实现基于端到端的流量控制功能。</p>
<p>第5层会话层：在两个节点之间建立端连接。为端系统的应用程序之间提供了对话控制机制。此服务包括建立连接是以全双工还是以半双工的方式进行设置，尽管可以在层4中处理双工方式 ；会话层管理登入和注销过程。它具体管理两个用户和进程之间的对话。如果在某一时刻只允许一个用户执行一项特定的操作，会话层协议就会管理这些操作，如阻止两个用户同时更新数据库中的同一组数据。</p>
<p>第6层表示层：主要用于处理两个通信系统中交换信息的表示方式。为上层用户解决用户信息的语法问题。它包括数据格式交换、数据加密与解密、数据压缩与终端类型的转换。</p>
<p>第7层应用层：OSI中的最高层。为特定类型的网络应用提供了访问OSI环境的手段。应用层确定进程之间通信的性质，以满足用户的需要。应用层不仅要提供应用进程所需要的信息交换和远程操作，而且还要作为应用进程的用户代理，来完成一些为进行信息交换所必需的功能。它包括：文件传送访问和管理FTAM、虚拟终端VT、事务处理TP、远程数据库访问RDA、制造报文规范MMS、目录服务DS等协议；应用层能与应用程序界面沟通，以达到展示给用户的目的。 在此常见的协议有:HTTP，HTTPS，FTP，TELNET，SSH，SMTP，POP3等。</p>
<h3 id="OSI参考模型各层功能"><a href="#OSI参考模型各层功能" class="headerlink" title="OSI参考模型各层功能"></a>OSI参考模型各层功能</h3><p>(1)物理层(Physical Layer)<br>物理层是OSI参考模型的最低层，它利用传输介质为数据链路层提供物理连接。<br>它主要关心的是通过物理链路从一个节点向另一个节点传送比特流，物理链路可能是铜线、卫星、微波或其他的通讯媒介。<br>它关心的问题有：多少伏电压代表1？多少伏电压代表0？时钟速率是多少？采用全双工还是半双工传输？总的来说物理层关心的是链路的机械、电气、功能和规程特性。</p>
<p>(2)数据链路层(Data Link Layer)<br>数据链路层是为网络层提供服务的，解决两个相邻结点之间的通信问题，传送的协议数据单元称为数据帧。<br>数据帧中包含物理地址（又称MAC地址）、控制码、数据及校验码等信息。该层的主要作用是通过校验、确认和反馈重发等手段，将不可靠的物理链路转换成对网络层来说无差错的数据链路。<br>此外，数据链路层还要协调收发双方的数据传输速率，即进行流量控制，以防止接收方因来不及处理发送方来的高速数据而导致缓冲器溢出及线路阻塞。</p>
<p>(3)网络层(Network Layer)<br>网络层是为传输层提供服务的，传送的协议数据单元称为数据包或分组。<br>该层的主要作用是解决如何使数据包通过各结点传送的问题，即通过路径选择算法（路由）将数据包送到目的地。<br>另外，为避免通信子网中出现过多的数据包而造成网络阻塞，需要对流入的数据包数量进行控制（拥塞控制）。<br>当数据包要跨越多个通信子网才能到达目的地时，还要解决网际互连的问题。</p>
<p>(4)传输层(Transport Layer)<br>传输层的作用是为上层协议提供端到端的可靠和透明的数据传输服务，包括处理差错控制和流量控制等问题。<br>该层向高层屏蔽了下层数据通信的细节，使高层用户看到的只是在两个传输实体间的一条主机到主机的、可由用户控制和设定的、可靠的数据通路。<br>传输层传送的协议数据单元称为段或报文。</p>
<p>(5)会话层(Session Layer)<br>会话层主要功能是管理和协调不同主机上各种进程之间的通信（对话），即负责建立、管理和终止应用程序之间的会话。会话层得名的原因是它很类似于两个实体间的会话概念。例如，一个交互的用户会话以登录到计算机开始，以注销结束。</p>
<p>(6)表示层(Presentation Layer)<br>表示层处理流经结点的数据编码的表示方式问题，以保证一个系统应用层发出的信息可被另一系统的应用层读出。<br>如果必要，该层可提供一种标准表示形式，用于将计算机内部的多种数据表示格式转换成网络通信中采用的标准表示形式。<br>数据压缩和加密也是表示层可提供的转换功能之一。</p>
<p>(7)应用层(Application Layer)<br>应用层是OSI参考模型的最高层，是用户与网络的接口。<br>该层通过应用程序来完成网络用户的应用需求，如文件传输、收发电子邮件等。</p>
<h3 id="TCP"><a href="#TCP" class="headerlink" title="TCP"></a>TCP</h3><p>TCP完成了OSI参考模型中的<strong>第四层传输层</strong>的功能，net模块简单来说就是TCP协议的node实现。</p>
<p>TCP（Transmission Control Protocol 传输控制协议）是一种面向连接的、可靠的、基于字节流的传输层通信协议，由IETF的RFC 793定义。</p>
<p>当应用层向TCP层发送用于网间传输的、用8位字节表示的数据流，TCP则把数据流分割成适当长度的报文段，最大传输段大小（MSS）通常受该计算机连接的网络的数据链路层的最大传送单元（MTU）限制。之后TCP把数据包传给IP层，由它来通过网络将包传送给接收端实体的TCP层。<br>TCP为了保证报文传输的可靠 [1]  ，就给每个包一个序号，同时序号也保证了传送到接收端实体的包的按序接收。然后接收端实体对已成功收到的字节发回一个相应的确认(ACK)；如果发送端实体在合理的往返时延(RTT)内未收到确认，那么对应的数据（假设丢失了）将会被重传。<br><em>TCP的可靠性虽然很好，但它也因此牺牲了效率，它比较适合于传输文件等场景。如果在对可靠性要求不高，但对效率要求很高的场景，如视频直播等，就可以使用UDP</em>。</p>
<h3 id="UDP"><a href="#UDP" class="headerlink" title="UDP"></a>UDP</h3><p>UDP 是User Datagram Protocol的简称， 中文名是用户数据报协议，是OSI（Open System Interconnection，开放式系统互联） 参考模型中一种无连接的传输层协议，提供面向事务的简单不可靠信息传送服务，IETF RFC 768是UDP的正式规范。UDP在IP报文的协议号是17。</p>
<p>UDP报文没有可靠性保证、顺序保证和流量控制字段等，可靠性较差。但是正因为UDP协议的控制选项较少，在数据传输过程中延迟小、数据传输效率高，适合对可靠性要求不高的应用程序，如音频、视频和普通数据在传送时使用UDP较多，或者可以保障可靠性的应用程序，如DNS、TFTP、SNMP等。</p>
<p>Nodejs也提供了UDP/Datagram模块，可以在需要使用UDP时调用。</p>

            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls"
                data-autoplay="false">
                <source type="audio/mpeg" src="">
            </audio>
            
            <ul id="audio-list" style="display:none">
                
                
                <li title='0' data-url='/statics/chengdu.mp3'></li>
                
                    
            </ul>
            
            
            
    <div id='gitalk-container' class="comment link"
        data-ae='true'
        data-ci='ec894e2b66f752e8b7fb'
        data-cs='3ccc2e92bb350688fe2c2dc2930189b62622bfb1'
        data-r='blog-comments'
        data-o='TriDiamond'
        data-a='TriDiamond'
        data-d='undefined'
    >Comments</div>


            
            
        </div>
        <div class="sidebar">
            <div class="box animated fadeInRight">
                <div class="subbox">
                    <img src="https://res.cloudinary.com/tridiamond/image/upload/v1573019751/TriDiamond_logo_ui_xeublz.jpg" height=300 width=300></img>
                    <p>张白告丶</p>
                    <span>Think like an artist, develop like an artisan</span>
                    <dl>
                        <dd><a href="https://github.com/zhanghao-web" target="_blank"><span
                                    class=" iconfont icon-github"></span></a></dd>
                        <dd><a href="" target="_blank"><span
                                    class=" iconfont icon-twitter"></span></a></dd>
                        <dd><a href="" target="_blank"><span
                                    class=" iconfont icon-stack-overflow"></span></a></dd>
                    </dl>
                </div>
                <ul>
                    <li><a href="/">149 <p>Articles</p></a></li>
                    <li><a href="/categories">23 <p>Categories</p></a></li>
                    <li><a href="/tags">47 <p>Tags</p></a></li>
                </ul>
            </div>
            
            
            
            <div class="box sticky animated fadeInRight faster">
                <div id="toc" class="subbox">
                    <h4>Contents</h4>
                    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#assert-断言"><span class="toc-number">1.</span> <span class="toc-text">assert (断言)</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#用法"><span class="toc-number">1.1.</span> <span class="toc-text">用法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用方式"><span class="toc-number">1.2.</span> <span class="toc-text">使用方式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#assert-deepStrictEqual"><span class="toc-number">1.3.</span> <span class="toc-text">assert.deepStrictEqual</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#assert-deepStrictEqual的用法"><span class="toc-number">1.4.</span> <span class="toc-text">assert.deepStrictEqual的用法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#path-路径"><span class="toc-number">2.</span> <span class="toc-text">path(路径)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#使用"><span class="toc-number">3.</span> <span class="toc-text">使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#URL模块"><span class="toc-number">4.</span> <span class="toc-text">URL模块</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#url-parse"><span class="toc-number">4.1.</span> <span class="toc-text">url.parse</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#new-URL"><span class="toc-number">4.2.</span> <span class="toc-text">new URL()</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#querystring模块"><span class="toc-number">5.</span> <span class="toc-text">querystring模块</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#querystring-parse"><span class="toc-number">5.1.</span> <span class="toc-text">querystring.parse</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#querystring-stringify"><span class="toc-number">5.2.</span> <span class="toc-text">querystring.stringify</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#net模块"><span class="toc-number">6.</span> <span class="toc-text">net模块</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#OSI参考模型"><span class="toc-number">6.1.</span> <span class="toc-text">OSI参考模型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#OSI参考模型分层"><span class="toc-number">6.2.</span> <span class="toc-text">OSI参考模型分层</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#OSI参考模型各层功能"><span class="toc-number">6.3.</span> <span class="toc-text">OSI参考模型各层功能</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#TCP"><span class="toc-number">6.4.</span> <span class="toc-text">TCP</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#UDP"><span class="toc-number">6.5.</span> <span class="toc-text">UDP</span></a></li></ol></li></ol>
                </div>
            </div>
            
            
        </div>
    </div>
</div>

    </div>
</div>
    <div id="back-to-top" class="animated fadeIn faster">
        <div class="flow"></div>
        <span class="percentage animated fadeIn faster">0%</span>
        <span class="iconfont icon-top02 animated fadeIn faster"></span>
    </div>
</body>
<footer>
    <p class="copyright" id="copyright">
        &copy; 2020
        <span class="gradient-text">
            张白告丶
        </span>.
        Powered by <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a>
        Theme
        <span class="gradient-text">
            <a href="https://github.com/TriDiamond/hexo-theme-obsidian" title="Obsidian" target="_blank" rel="noopener">Obsidian</a>
        </span>
        <small><a href="https://github.com/TriDiamond/hexo-theme-obsidian/blob/master/CHANGELOG.md" title="v1.4.3" target="_blank" rel="noopener">v1.4.3</a></small>
    </p>
</footer>

<script type="text/javascript" src="https://cdn.bootcss.com/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script>
  MathJax.Hub.Config({
    "HTML-CSS": {
      preferredFont: "TeX",
      availableFonts: ["STIX", "TeX"],
      linebreaks: {
        automatic: true
      },
      EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
    },
    tex2jax: {
      inlineMath: [
        ["$", "$"],
        ["\\(", "\\)"]
      ],
      processEscapes: true,
      ignoreClass: "tex2jax_ignore|dno",
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      noUndefined: {
        attributes: {
          mathcolor: "red",
          mathbackground: "#FFEEEE",
          mathsize: "90%"
        }
      },
      Macros: {
        href: "{}"
      }
    },
    messageStyle: "none"
  });
</script>
<script>
  function initialMathJax() {
    MathJax.Hub.Queue(function () {
      var all = MathJax.Hub.getAllJax(),
        i;
      // console.log(all);
      for (i = 0; i < all.length; i += 1) {
        console.log(all[i].SourceElement().parentNode)
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  }

  function reprocessMathJax() {
    if (typeof MathJax !== 'undefined') {
      MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
    }
  }
</script>



    
<link rel="stylesheet" href="//cdn.bootcss.com/gitalk/1.5.0/gitalk.min.css">

    
<script src="//cdn.bootcss.com/gitalk/1.5.0/gitalk.min.js"></script>



<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="/js/plugin.js"></script>
<script src="/js/obsidian.js"></script>
<script src="/js/jquery.truncate.js"></script>
<script src="/js/search.js"></script>


<script src="//cdn.bootcss.com/typed.js/2.0.10/typed.min.js"></script>


<script src="//cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>


<script src="//cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js"></script>


<script src="https://cdn.bootcss.com/codemirror/5.48.4/codemirror.min.js"></script>

    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/javascript/javascript.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/css/css.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/xml/xml.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/htmlmixed/htmlmixed.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/clike/clike.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/php/php.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/shell/shell.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/python/python.min.js"></script>




    
<script src="/js/busuanzi.min.js"></script>

    <script>
        $(document).ready(function () {
            if ($('span[id^="busuanzi_"]').length) {
                initialBusuanzi();
            }
        });
    </script>



<link rel="stylesheet" href="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe.min.css">
<link rel="stylesheet" href="//cdn.bootcss.com/photoswipe/4.1.3/default-skin/default-skin.min.css">


<script src="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe.min.js"></script>
<script src="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>



    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="//www.googletagmanager.com/gtag/js?id=UA-149874671-1"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'UA-149874671-1');
    </script>





<script>
    function initialTyped () {
        var typedTextEl = $('.typed-text');
        if (typedTextEl && typedTextEl.length > 0) {
            var typed = new Typed('.typed-text', {
                strings: ["Think like an artist, develop like an artisan", "艺术家思维去思考问题，工匠创造精神去开发"],
                typeSpeed: 90,
                loop: true,
                loopCount: Infinity,
                backSpeed: 20,
            });
        }
    }

    if ($('.article-header') && $('.article-header').length) {
        $(document).ready(function () {
            initialTyped();
        });
    }
</script>




</html>
